extends Node

var itemsData = []
var itemsDataDict = {}
var weaponsData = []
var weaponsDataDict = {}
var equipmentsData = []
var equipmentsDataDict = {}
var playerAcceptMoveInput = true
var uiAcceptInput = true

var playerData 
var partnersData = []

var enterBattleBgImage = null


func loadConfig(csvFileName, clz):
	var data:Array = Global.loadCSV(Global.pathJoin(Consts.configRootPath, csvFileName))
	var result = Global.parseCSV(data, clz)
	clz.configs = result[0]
	clz.configsDict = result[1]
	if clz.has_method("processData"):
		clz.processData()


func onGetItem(itemType, itemId, count):
	if itemType == Consts.ITEM_TYPE_CONSUMABLE:
		var itemConfig = ConfigClasses.ItemConfig.configsDict[itemId]
		if itemConfig != null:
			tryAddItem(itemConfig, count)
			
	elif itemType == Consts.ITEM_TYPE_WEAPON:
		for index in range(count):
			var weaponConfig = ConfigClasses.WeaponConfig.configsDict[itemId]
			var weaponData = CustomClasses.WeaponData.new()
			weaponData.lv = 1
			weaponData.config = weaponConfig
			
			weaponsData.append(weaponData)
			if not weaponsDataDict.has(weaponConfig.id):
				weaponsDataDict[weaponConfig.id] = []
			weaponsDataDict[weaponConfig.id].append(weaponData)
		
	elif itemType == Consts.ITEM_TYPE_EQUIPMENT:
		for index in range(count):
			var equipmentConfig = ConfigClasses.EquipmentConfig.configsDict[itemId]
			var equipmentData = CustomClasses.EquipmentData.new()
			equipmentData.config = equipmentConfig
			
			equipmentsData.append(equipmentData)
			if not equipmentsDataDict.has(equipmentConfig.id):
				equipmentsDataDict[equipmentConfig.id] = []
			equipmentsDataDict[equipmentConfig.id].append(equipmentData)


func tryAddItem(itemConfig, count):
	if itemsDataDict.has(itemConfig.id):
		var currentItemData = itemsDataDict[itemConfig.id]
		currentItemData.count += count
	else:
		var newItemData = CustomClasses.ItemData.new(itemConfig, count)
		itemsDataDict[itemConfig.id] = newItemData
		itemsData.append(newItemData) 
		

func addWeapon(weaponData):
	weaponsData.append(weaponData)
	if not weaponsDataDict.has(weaponData.config.id):
		weaponsDataDict[weaponData.config.id] = []
	weaponsDataDict[weaponData.config.id].append(weaponData)
	
	
func addEquipment(equipmentData):
	equipmentsData.append(equipmentData)
	if not equipmentsDataDict.has(equipmentData.config.id):
		equipmentsDataDict[equipmentData.config.id] = []
	equipmentsDataDict[equipmentData.config.id].append(equipmentData)
		
	
	
	
